<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // let const
        // es6中新增的创建变量 和 常量
        var obj = {
            name: 'obj',
            fn: function () {
                console.log(this.name);
                console.log(() => {
                    console.log(this.name, '2');
                });
                return () => {
                    console.log(this.name, '2');
                }
            },
            fn2: () => {
                console.log(this.name);
            }
        }
        var name = 'windows'
        obj.fn()()
        obj.fn2()

        var ary = [1, 2, 3, 4, 5];
        var [n, m, ...x] = ary; // 左侧右侧的值一样的时候叫做解构 [] = []
        // ...拓展运算符 把剩余的都存到 一个数组里 但是他只能出现在最后
        var [a, , b = 8] = ary // 不需要的可以空开 等号 默认赋值
        var arr = [1, 2, [3, 4, [5, 6]]]
        var [x, , [, , [y]]] = arr; // 多维数组的结构赋值

        // 二次解构
        var obj = {
            name: 'zs',
            age: 18,
            sex: 'boy',
            firends: ['ls', 'wu', 'zl']
        }
        var {
            name: aa,
            firends: [one, two] // 二次解构
        } = obj

        // 形参解构
        var data = {
            code: 200,
            data: [{
                time: '2022-10-03',
                id: 1
            }, {
                time: '2023-08-13',
                id: 2
            }, {
                time: '2023-07-27',
                id: 3
            }],
            message: 'success'
        }
        var { code, data: timeData } = data
        console.log(code, timeData);
        if (code === 200) {
            timeData.forEach(({id, time}) => { // 形参解构
                console.log(id, time);
            })
        }

        // 剩余运算符
        var obj = {name: 'lzw', age: 16};
        var objClone = {...obj, sex: 'boy', age: 18}
        console.log(objClone);
    </script>
</body>

</html>